package lesson;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        TreeMap<String, String> students = new TreeMap<>();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            students.clear();
            int n = scanner.nextInt();
            String id, name;
            for (int i = 0; i < n; i++) {
                id = scanner.next();
                name = scanner.next();
                students.put(id, name);
            }
            id = scanner.next();
            System.out.println(id + " " + students.get(id));
            students.remove(id);
            System.out.println(students.size());


            Set<String> keySet = students.keySet();
            Iterator<String> iter = keySet.iterator();
            //Iterator<String> iter = map.keySet().iterator();
            while (iter.hasNext()) {
                String str = iter.next();
                System.out.println(str + " " + students.get(str));
            }
        }
    }
}